package com.netease.xone.view;


import android.content.Context;
import android.support.v4.view.ViewPager;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

public abstract class ContainerView extends RelativeLayout {
    public static final int ID_PAGER        = 0x10001010;
    public static final int ID_BOTTOM       = 0x10001020;

    protected ViewPager mViewPager = null;
    protected ViewGroup mBottom = null;

    public ContainerView(Context context) {
        super(context);
    }

    protected abstract ViewPager onInitPager(Object obj);

    protected abstract ViewGroup onInitBottom(Object obj);

    protected abstract void setPagerAndBottom(ViewPager viewPager, ViewGroup bottom);

    public ViewPager getViewPager() {
        return mViewPager;
    }
    
    public ViewGroup getNav() {
        return mBottom;
    }

    public void onInitPagerAndBottom(Object obj) {
        final ViewPager viewPager = onInitPager(obj);
        final ViewGroup viewBotton = onInitBottom(obj);
        LayoutParams params;

        if (null != viewPager && null != viewBotton) {
            viewPager.setId(ID_PAGER);
            viewBotton.setId(ID_BOTTOM);

            setPagerAndBottom(viewPager, viewBotton);

            params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
            params.addRule(RelativeLayout.ABOVE, ID_BOTTOM);
            params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            addView(viewPager, params);

            params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
            params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            addView(viewBotton, params);
        }
    }
}
